package com.neusoft.controller.check;

import com.neusoft.bean.PageBean;
import com.neusoft.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@RestController
@RequestMapping("/check")
@CrossOrigin
public class CheckController {
    @Autowired
    private CheckService checkService;


    @GetMapping("/getList")
    public PageBean getList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "5") Integer pageSize,
            String realName,
            String checkTime) {
        return checkService.getList(page, pageSize, realName, checkTime);
    }


    @GetMapping("/detail")
    public Map<String,Object> getCheckDetail(Integer id){
        Map<String, Object> checkDetail = checkService.getCheckDetail(id);
        List<Map<String,Object>> list = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
        map.put("tech_code",checkDetail.get("tech_code"));
        map.put("tech_name",checkDetail.get("tech_name"));
        map.put("tech_format",checkDetail.get("tech_format"));
        map.put("tech_type",checkDetail.get("tech_type"));
        map.put("price_type",checkDetail.get("price_type"));
        map.put("realname",checkDetail.get("realname"));
        map.put("check_state",checkDetail.get("check_state"));
        list.add(map);
        checkDetail.put("creation_time",((LocalDateTime)checkDetail.get("creation_time")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        checkDetail.put("check_time",((LocalDateTime)checkDetail.get("check_time")).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        checkDetail.put("techList",list);
        return checkDetail;
    }
}
